// pages/program/index.js
const { gaokaoTime } = require('../../api/api')
Page({

  /**
   * 页面的初始数据
   */
  data: {
    list: ['高考时间', '成绩查询', '志愿填报', '录取时间'],
    currentRegion: {},
    timeList: [
      //   {
      //   date: '6月7日',
      //   time: '<p>09:00-11:30</p> <p>15:00-17:00</p>',
      //   name: '<p>语文</p> <p>数学</p>'
      // }, {
      //   date: '6月8日',
      //   time: '<p>09:00-10:15</p><p>15:00-17:00</p>',
      //   name: '<p>物理/历史</p> <p>外语</p>'
      // }, {
      //   date: '6月9日',
      //   time: '<p>08:30-09:45</p><p>11:00-12:15</p><p>14:30-15:45</p><p>17:00-18:15</p>',
      //   name: '<p>语文</p> <p>地理</p><p>思想政治</p><p>生物</p>'
      // }
    ],
    timeColumns: [
      {
        label: '日期',
        prop: 'date',
        fontSize: '',
        width: '226',
        align: 'center',
        color: '#000000',
        padding: '20rpx'

      },
      {
        label: '时间',
        prop: 'time',
        fontSize: '',
        width: '226',
        align: 'center',
        color: '#000000',
        padding: '20rpx'

      },
      {
        label: '科目',
        prop: 'name',
        fontSize: '',
        width: '226',
        align: 'center',
        color: '#000000',
        padding: '20rpx'

      }
    ],
    timeSetting: {
      theadBgColor: 'transparent',
      theadColor: '#808080',
      theadFontWeight: '500',
      theadHeight: '72rpx',
      tableRadius: '0 0 20rpx 20rpx'
    },
    collegeFillList: [
    ],
    collegeFillColumns: [{
      label: '批次填报',
      prop: 'batch',
      fontSize: '',
      width: '246',
      align: 'center',
      color: '#808080',
      padding: '20rpx'

    }, {
      label: '开始填报',
      prop: 'startTime',
      fontSize: '',
      width: '206',
      align: 'center',
      color: '#000000'
    },
    {
      label: '截至填报',
      prop: 'endTime',
      fontSize: '',
      width: '226',
      align: 'center',
      color: '#000000'
    },
    ],
    collegeFillSetting: {
      theadBgColor: 'transparent',
      theadFontWeight: '500',
      theadColor: '#000000',
      theadHeight: '72rpx',
      tableRadius: '0 0 20rpx 20rpx'
    },
    entollTimeList: [
      //   {
      //   id: 1,
      //   name: '艺术类提前批',
      //   time: '7月10日早8点前'
      // }, {
      //   id: 1,
      //   name: '艺术类本科提前批',
      //   time: '7月14日晚'
      // }, {
      //   id: 1,
      //   name: '普通类本科批',
      //   time: '7月30日晚'
      // }, {
      //   id: 1,
      //   name: '体育类本科批',
      //   time: '7月15日晚'
      // }, {
      //   id: 1,
      //   name: '艺术类本科批-省考',
      //   time: '7月17日晚'
      // }, {
      //   id: 1,
      //   name: '艺术类本科批-校考',
      //   time: '7月27日晚'
      // }, {
      //   id: 1,
      //   name: '高水平运动队、高水平艺术团、高校农村专项计划',
      //   time: '7月22日8点前'
      // }, {
      //   id: 1,
      //   name: '地方农村专项计划',
      //   time: '7月22日8点前'
      // }, {
      //   id: 1,
      //   name: '本科批降分录取',
      //   time: '8月10日晚'
      // }, {
      //   id: 1,
      //   name: '普通类高职（专科）批',
      //   time: '8月14日晚'
      // }, 
    ],
    entollColumns: [{
      label: '批次填报',
      prop: 'batch',
      fontSize: '',
      width: '340',
      align: 'center',
      color: '#000000',
      padding: '20rpx 32rpx'
    }, {
      label: '查询时间',
      prop: 'time',
      fontSize: '',
      width: '338',
      align: 'center',
      color: '#000000'

    },
    ],
    entollSetting: {
      theadBgColor: 'transparent',
      theadColor: '#808080',
      theadFontWeight: '500',
      theadHeight: '72rpx',
      tableRadius: '0 0 20rpx 20rpx'
    },
    currentIndex: 0,
    cityList: [],
    visible: false,
    province: {},
    bottomLift: getApp().globalData.bottomLift
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    const province = {
      value: wx.getStorageSync('userCitys').name,
      id: wx.getStorageSync('userCitys').code
    }
    this.setData({
      currentRegion: wx.getStorageSync('userCitys'),
      province
    })
    this.getCityList()
    this.getGaokaoTime()
  },
  async getCityList() {
    const result = wx.getStorageSync('cityList') || await getApp().getCityList()
    const cityList = result.map((item) => {
      return {
        id: item.id,
        value: item.title
      }
    })
    this.setData({
      cityList: cityList
    })
  },
  //  获取高考日程信息
  async getGaokaoTime() {
    const { province } = this.data
    const { result } = await gaokaoTime(province.id)
    const { entollTimeList, collegeFillList } = result
    result.timeInfoList.map(item => {
      item.time = ''
      item.name = ''
      item.list.map(e => {
        item.time += `<p>${e.gkTimeCn}</p>`
        item.name += `<p>${e.gkSubject}</p>`
      })
      delete item.list
    })
    this.setData({
      timeList: result.timeInfoList,
      scoreInquiry: result.scoreInquiryList[0],
      entollTimeList,
      collegeFillList
    })
  },
  changeIndex(e) {
    const { index } = e.currentTarget.dataset
    this.setData({
      currentIndex: index
    })
  },
  goto(e) {
    const { url } = e.currentTarget.dataset
    wx.navigateTo({
      url
    })
  },
  toggleFalse() {
    this.setData({
      visible: false
    })
  },
  toggle() {
    this.setData({
      visible: !this.data.visible
    })
  },
  confirm(e) {
    const {
      value,
      key
    } = e.detail
    this.setData({
      [key]: value
    })
    this.getGaokaoTime()
  },
  copy(e) {
    const text = e.currentTarget.dataset.text
    getApp().copy(text)
  },
  call(e) {
    const text = e.currentTarget.dataset.text
    getApp().call([text])
  },
  onShareAppMessage() {
    return {
      title: '高考日程',
      imageUrl: 'https://ehsimg.oss-cn-beijing.aliyuncs.com/images/static/users/shareImg.jpg'
    }
  }
})